import { getTokenInfo } from '@/utils/storage'
import { combineReducers } from 'redux'
import { profile } from './profile'

const initialState = getTokenInfo()

function token(state = initialState, action) {
  const { type, payload } = action
  if (type === 'login/token') {
    return {
      ...state,
      user: { ...payload },
    }
  }
  if (action.type === 'login/logout') {
    return {}
  }

  return state
}

const rootReducer = combineReducers({
  token,
  profile,
})

export default rootReducer
